#include <wx/wx.h>
#include <wx/cmdline.h>
#include <wx/filename.h>
#include "verinfo.h"
#include "txt2dict.h"
#include "converter.h"

IMPLEMENT_APP_CONSOLE( Txt2DictConsole )

void Txt2DictConsole::convert() {
    Converter converter(txtpath, daodictpath);
    converter.start();
}

void Txt2DictConsole::OnInitCmdLine(wxCmdLineParser& parser) {
    parser.SetSwitchChars(_T("-"));
    
    wxString logo = _T("txt2dao ");
    logo= logo + _T(PRODUCT_VERSION_NUMBER "\n" PRODUCT_COPYRIGHT) + 
            _T("\n\nConvert .txt dictionary contents to Daodict format"
               " (If the .daodict file "
               "already exists, contents will be added without modify current .daodict contents.\n");
    parser.SetLogo(logo);
    
    parser.AddParam(_T("<.txt file>"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY);
    parser.AddParam(_T("<.daodict file>"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_OPTION_MANDATORY);
    return wxAppConsole::OnInitCmdLine(parser);
}

bool Txt2DictConsole::OnCmdLineParsed(wxCmdLineParser& parser) {
    txtpath = parser.GetParam();
    daodictpath = parser.GetParam(1);
    
    return wxAppConsole::OnCmdLineParsed(parser);
}

int Txt2DictConsole::OnRun() {
    convert();
    return 0;
}
